package com.sample.generator.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.sample.generator.io.InputStreamProvider;

public class PropertiesLoader {

	private InputStreamProvider provider;

	public PropertiesLoader(InputStreamProvider provider) {

		if (provider == null) {
			throw new IllegalArgumentException("Argument provider is null.");
		}
		this.provider = provider;
	}

	public Properties loadProperties(String name) throws IOException {

		InputStream is = null;
		try {
			is = provider.open(name);
			Properties props = new Properties();
			props.load(is);
			return props;
		} finally {
			if (is != null) {
				is.close();
			}
		}
	}
}
